<%@page import="com.antexpress.pojo.Employee"%>
<%@page import="com.antexpress.bean.Authentication"%>
<%@page import="com.antexpress.common.Const"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Courier -- Ant Express</title>
        <link rel="shortcut icon" href="static/img/ant-logo.png">
        <link rel="shortcut icon" href="static/img/ant-logo.png">
        <link href="static/css/style.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/normalize.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/default.css" rel="stylesheet" type="text/css"/>
        <link href="static/dist/css/jquery.secretnav.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/demo.css" rel="stylesheet" type="text/css"/>
        <link href="static/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/edbox.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/selectpage.css" rel="stylesheet" type="text/css"/>
        <link href="static/css/stickysort.css" rel="stylesheet" type="text/css"/>
    </head>
    <body id="body">
        <%
            if(!Authentication.isLogin(session)) {
                response.sendRedirect("index.jsp");
                return;
            }
            Employee emp = (Employee)session.getAttribute(Const.CURRENT_USER);
            if(!Authentication.isEmployeeAdmin(emp)){
                response.sendRedirect("404.jsp");
                return;
            }
        %>
                <div class="sn-outer-wrapper sn-moveleft modalview">
            <div class="sn-content-wrapper transform" style="cursor: default;">
                <div id="content" style="top: 0px;">
                    <jsp:include page="ui/header.jsp"/>
                    <div class="container-nav">
                        <div class="container">
                            <button class="open btn btn-default bt-open" title="Menu"><i class="fa fa-bars" aria-hidden="true"></i></button>
                            <%
                                if (Authentication.isExpressLogisticsManager(emp)) {
                                    out.println("<a href='courier.jsp' class='content-nav-bt'>Courier Management</a>");
                                    out.println("<a href='parse_district.jsp' class='content-nav-bt'>Area Infomation Upload</a>");
                                }
                            %>
                        </div>
                    </div>
                    <div class="container" style="text-align: left;color: #000">
                        <h1 class="heading"><i class="fa fa-archive" aria-hidden="true"></i> Courier Management</h1>
                        <div class="content-div">
                            <div class="courier-top-box">
                                <div style="display: inline-block">
                                    <button class="btn btn-primary" id="select-all-bt" select="1" onclick="selectAllCourier()" title="Select all"><i class="fa fa-check" aria-hidden="true"></i></button>&nbsp;&nbsp;
                                    <button class="btn btn-danger" title="Delete courier" edbox data-box-target="#courier-batch-delete-box"><i class="fa fa-trash" aria-hidden="true"></i></button>
                                </div>
                                <div style="display: inline-block;float:right;text-align: right">
                                    <form onsubmit="return false;">
                                        <input type="text" placeholder="Province" id="sh-province" class="searchInput"/>
                                        <input type="text" placeholder="City" id="sh-city" class="searchInput"/>
                                        <input type="text" placeholder="District" id="sh-district" class="searchInput"/>
                                        <input type="text" placeholder="Town" id="sh-town" class="searchInput"/>
                                        <button id="search-courier" type="submit" class="btn btn-primary" title="Search"><i class="fa fa-search" aria-hidden="true"></i></button>
                                        <button class="btn btn-default" title="Refresh" onclick="getCourierList()"><i class="fa fa-refresh" aria-hidden="true"></i></button>
                                    </form>
                                </div>
                                <input type="hidden" id="search-c-province"/>
                                <input type="hidden" id="search-c-city"/>
                                <input type="hidden" id="search-c-district"/>
                                <input type="hidden" id="search-c-town"/>
                                <input type="hidden" id="search-c-page" value="1"/>
                            </div>
                            <table id="courier-table" class="pub-table pub-table-hover">
                                <thead>
                                    <tr>
                                        <th style="min-width: 30px;">&nbsp;<i class="fa fa-check-square-o" aria-hidden="true"></i>&nbsp;</th>
                                        <th>Province</th><th>City</th><th>District</th><th>Town</th><th>Name</th><th>Mobile</th>
                                        <th style="min-width: 80px;">&nbsp;<i class="fa fa-pencil-square-o" aria-hidden="true"></i>&nbsp;</th>
                                    </tr>
                                </thead>
                                <tbody id="courier-table-body">
                                </tbody>
                            </table>
                            <div id="searchResultMsg" class="content-center table-result-msg">
                                
                            </div>
                            <div class="content-center">
                                <ul class="pagination" id="courierPag"></ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="sn-nav-wrapper">
                <nav id="nav" class="sn-nav left vertical">
                    <jsp:include page="ui/nav.jsp"/>
                </nav>
            </div>
        </div>  
        <!--模态框部分--><!--模态框部分--><!--模态框部分--><!--模态框部分--><!--模态框部分--><!--模态框部分--><!--模态框部分-->
        
        <!-- 展示派送员信息模态框 -->
        <div id="courier-show-box" class="ed-div" style="display:none;">
            <h3 class="subheading" style="margin: 3px;"><i class="fa fa-info-circle" aria-hidden="true"></i> Courier Details</h3><br/>
            <table class="model-form-table" style="color: black;">
                <tr>
                    <td>Province</td>
                    <td id="courier-show-province"></td>
                </tr>
                <tr>
                    <td>City</td>
                    <td id="courier-show-city"></td>
                </tr>
                <tr>
                    <td>District</td>
                    <td id="courier-show-district"></td>
                </tr>
                <tr>
                    <td>Town</td>
                    <td id="courier-show-town"></td>
                </tr>
                <tr>
                    <td>Name</td>
                    <td id="courier-show-name"></td>
                </tr>
                <tr>
                    <td>Gender</td>
                    <td id="courier-show-gender"></td>
                </tr>
                <tr>
                    <td>Mobile</td>
                    <td id="courier-show-mobile"></td>
                </tr>
                <tr>
                    <td>Email</td>
                    <td id="courier-show-email"></td>
                </tr>
                <tr>
                    <td>Status</td>
                    <td id="courier-show-status"></td>
                </tr>
            </table>
            <input type="button" id="bt-add-courier-cancel" onclick="$.edbox('close');" class="btn btn-default" value="Close"/>
        </div>
        <!-- 展示员工信息模态框 结束 -->     
        
        <!-- 修改员工的模态框 -->
        <div id="courier-edit-box" class="ed-div" style="display:none;">
            <h3 class="subheading" style="margin: 3px;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit Distribution</h3><br/>
            
            <form onsubmit="return false;" id="editCourierForm">
            <h4 class="subTitle" style="float: left;margin: 10px;"><i class="fa fa-user" aria-hidden="true"></i> Distribution Information</h4>
            <table class="model-form-table" style="color: black;">
                <tr>
                    <td>Province</td>
                    <td id="disedit-courier-province" style="text-align: left;padding-left: 20px;"></td>
                </tr>
                <tr>
                    <td>City</td>
                    <td id="disedit-courier-city" style="text-align: left;padding-left: 20px;"></td>
                </tr>
                <tr>
                    <td>District</td>
                    <td id="disedit-courier-district" style="text-align: left;padding-left: 20px;"></td>
                </tr>
                <tr>
                    <td>Town</td>
                    <td id="disedit-courier-town" style="text-align: left;padding-left: 20px;"></td>
                    
                </tr>
                <tr>
                    <td>Name</td>
                    <td style="text-align: left;padding-left: 20px;">
                        <input type="text" id="edit-courier-name" class="input-md-width">
                    </td>
                </tr>
            </table><br/>
            <div class="content-center" style="margin: 10px;">
                <input type="hidden" id="disedit-town-id">
                <input type="submit" onclick="updateCourier()" class="btn btn-primary" value=" Save "/>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" id="bt-edit-courier-cancel" onclick="$.edbox('close');" class="btn btn-default" value="Cancel"/>
            </div>
            </form>
        </div>
        <!-- 修改员工的模态框 结束 -->
        
        <!-- 删除派送员的模态框 -->
        <div id="courier-delete-box" class="ed-div" style="display:none;">
            <h3 class="subheading" style="margin-top: 20px;">Do you want to remove the courier form the town?</h3><br/>
            <div class="content-center" style="margin: 10px;">
                <form onsubmit="return false;">
                    <input type="hidden" id="courier-delete-town" name ="town"/>
                    <input type="submit" onclick="deleteCourier()" class="btn btn-danger" value=" Delete "/>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="button" id="bt-delete-courier-cancel" onclick="$.edbox('close');" class="btn btn-default" value="Cancel"/>
                </form>
            </div>
        </div>
        <!-- 删除派送员的模态框 结束 -->
        
        <!-- 删除选中派送员的模态框 -->
        <div id="courier-batch-delete-box" class="ed-div" style="display:none;">
            <h3 class="subheading" style="margin-top: 20px;">Do you want to remove the couriers form the towns?</h3><br/>
            <div class="content-center" style="margin: 10px;">
                <form onsubmit="return false;">
                    <input type="submit" onclick="batchDelete()" class="btn btn-danger" value=" Delete "/>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <input type="button" id="bt-batch-delete-emp-cancel" onclick="$.edbox('close');" class="btn btn-default" value="Cancel"/>
                </form>
            </div>
        </div>
        <!-- 删除选中派送员的模态框 结束-->
        
        <!-- 上传文件的模态框-->
        <div id="uploadAreaInfo" class="ed-div" style="display:none;">
            <form id="uploadForm" enctype="multipart/form-data">  
                上传文件:<input id="file" type="file" name="file"/>  
            </form> 
            <button id="upload">上传文件</button>
        </div>
        <!-- 上传文件的模态框 结束-->
        
        <!--模态框部分结束--><!--模态框部分结束--><!--模态框部分结束--><!--模态框部分结束--><!--模态框部分结束--><!--模态框部分结束--><!--模态框部分结束--><!--模态框部分结束-->
                
        <script src="static/js/modernizr.custom.25376.js" type="text/javascript"></script>
        <script src="static/js/jquery.js" type="text/javascript"></script>
        <script src="static/js/common-script.js" type="text/javascript"></script>
        <script src="static/dist/js/jquery.secretnav.js" type="text/javascript"></script>
        <script src="static/js/jquery.ba-throttle-debounce.min.js" type="text/javascript"></script>
        <script src="static/js/jquery.edbox.js" type="text/javascript"></script>
        <script src="static/js/selectpage.js" type="text/javascript"></script>
        <script src="static/js/jquery.stickysort.js" type="text/javascript"></script>
        <script src="static/js/jqPaginator.js" type="text/javascript"></script>
        <script src="static/js/center-loader.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function() {
                menu();
                $('#courier-table').stickySort();
                buildCourierPag(1,1);
                getCourierSelect();
                initSelect();
                getProvinceSelect();
            });
            
            
            
            function initSelect(){
                $('#sh-city').selectPage({
                    showField: 'name',
                    keyField: 'id',
                    data: [],
                    eSelect: function (data) {
                        if(data){
                            var cid = data.id;
                            $.ajax({
                                url: "${pageContext.request.contextPath}/area/list_district_by_cityID.do",
                                data: {"cid":cid},
                                type: "POST",
                                dataType: "json",
                                success: function(result) {
                                    if(result.status === 1) {
                                        $('#sh-district').selectPageData(result.data);
                                    }
                                }
                            });
                        }
                    },
                    eClear: function(){//清空时，同时清空城市内容
                        $('#sh-district').selectPageClear();
                        $('#sh-district').selectPageData([]);
                        $('#sh-town').selectPageClear();
                        $('#sh-town').selectPageData([]);
                    }
                });
                
                $('#sh-district').selectPage({
                    showField: 'name',
                    keyField: 'id',
                    data: [],
                    eSelect: function (data) {
                        if(data){
                            var did = data.id;
                            $.ajax({
                                url: "${pageContext.request.contextPath}/area/list_town_by_districtID.do",
                                data: {"did":did},
                                type: "POST",
                                dataType: "json",
                                success: function(result) {
                                    if(result.status === 1) {
                                        $('#sh-town').selectPageData(result.data);
                                    }
                                }
                            });
                        }
                    },
                    eClear: function(){//清空时，同时清空城市内容
                        $('#sh-town').selectPageClear();
                        $('#sh-town').selectPageData([]);
                    }
                    
                });
                $('#sh-town').selectPage({
                    showField: 'name',
                    keyField: 'id',
                    data: []
                });
            }
            
            function getProvinceSelect() {
                var provinces = {};
                $.ajax({
                    url: "${pageContext.request.contextPath}/area/list_all_province.do",
                    type: "POST",
                    dataType: "json",
                    success: function(result) {
                        if(result.status === 1) {
                            provinces = result.data;
                            initProvinceSelect(provinces);
                        }
                    }
                });
            }
            
            function initProvinceSelect(provinces){
                $('#sh-province').selectPage({
                    showField: 'name',
                    keyField: 'id',
                    data: provinces,
                    eSelect: function (data) {
                        if(data){
                            var pid = data.id;
                            $.ajax({
                                url: "${pageContext.request.contextPath}/area/list_city_by_provinceID.do",
                                data: {"pid":pid},
                                type: "POST",
                                dataType: "json",
                                success: function(result) {
                                    if(result.status === 1) {
                                        $('#sh-city').selectPageData(result.data);
                                    }
                                }
                            });
                        }
                    },
                    eClear: function(){//清空时，同时清空城市内容
                        $('#sh-city').selectPageClear();
                        $('#sh-city').selectPageData([]);
                        $('#sh-district').selectPageClear();
                        $('#sh-district').selectPageData([]);
                        $('#sh-town').selectPageClear();
                        $('#sh-town').selectPageData([]);
                    }
                });
            }
            
            function getCourierSelect() {
                var couriers = {};
               $.ajax({
                    url: "${pageContext.request.contextPath}/courier/list_all_courier.do",
                    type: "POST",
                    dataType: "json",
                    success: function(result) {
                        if(result.status === 1) {
                            couriers = result.data;
                            initCourierSelect(couriers);
                        }
                    }
                });
            }
            
            function initCourierSelect(couriers) {
                $('#edit-courier-name').selectPage({
                    showField : 'name',
                    keyField : 'id',
                    pageSize : 10,
                    data : couriers,
                    formatItem : function(data){
                        var mobile="Not set mobile no.!";
                        if(data.mobile!==null)
                            mobile = data.mobile;
                        return data.name + '(' + mobile + ')';
                    }
                });
            }
            
            function buildCourierPag(totalPages, currentPage) {
                $('#courierPag').jqPaginator({
                    totalPages: totalPages,
                    visiblePages: 5,
                    currentPage: currentPage,

                    first: '<li class="first"><a href="javascript:void(0);">First</a></li>',
                    prev: '<li class="prev"><a href="javascript:void(0);">Previous</a></li>',
                    next: '<li class="next"><a href="javascript:void(0);">Next</a></li>',
                    last: '<li class="last"><a href="javascript:void(0);">Last</a></li>',
                    page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
                    onPageChange: function (num) {
                        $("#search-c-page").val(num);
                        getCourierList();
                    }
                });
            }
            
            /*获取派送员列表，pageNo-页数*/
            function getCourierList(){
                $("#searchResultMsg").empty();
                $('#body').loader('show','<i class="fa fa-2x fa-spinner fa-pulse"></i>');
                $.ajax({
                    url: "${pageContext.request.contextPath}/courier/list_courier.do",
                    data:{
                        "province": $("#search-c-province").val(),
                        "city": $("#search-c-city").val(),
                        "district": $("#search-c-district").val(),
                        "town": $("#search-c-town").val(),
                        "pageNo": $("#search-c-page").val()
                    },
                    type: "POST",
                    dataType: "json",
                    success: function(result) {
                        if(result.status === 1) {
                            var courierList = result.data.list;
                            if(courierList.length===0){
                                $("#searchResultMsg").append("<i class='fa fa-exclamation-circle' aria-hidden='true'></i> Sorry, no records!");
                            }
                            buildCourierTable(courierList);
                            var totalPages = 1;
                            if(result.data.totalPages!==0)
                                totalPages = result.data.totalPages;
                            $('#courierPag').jqPaginator('option', {
                                totalPages: totalPages,
                                currentPage: result.data.pageNo
                            });
                        }else {
                            $.edbox({ danger: result.msg });
                        }
                        $('#body').loader('hide');
                    },
                    error: function() {
                        $('#body').loader('hide');
                        $.edbox({ danger: "Opps, records got failed!" });
                    }
                });
            }
            
            /*初始化创建员工表格*/
            function buildCourierTable(courierList) {
                $("#courier-table-body").empty();
                var rowNum = 0;
                $.each(courierList, function(){
                    rowNum++;
                    var courierCheckbox = $("<td>").append("<input type='checkbox' value='"+this.id+"' name='delCourier'/>");
                    var province = $("<td>").append(this.mapTown.mapDistrict.mapCity.mapProvince.name);
                    var modelProvince = this.mapTown.mapDistrict.mapCity.mapProvince.name;
                    var city = $("<td>").append(this.mapTown.mapDistrict.mapCity.name);
                    var modelCity = this.mapTown.mapDistrict.mapCity.name;
                    var district = $("<td>").append(this.mapTown.mapDistrict.name);
                    var modelDistrict = this.mapTown.mapDistrict.name;
                    var modelTown = this.mapTown.name;
                    var townId = this.mapTown.id;
                    var town = $("<td>").append(modelTown);
                    var courId = "";
                    var courName = "No courier!";
                    var courMobile = "";
                    var gender = "";
                    var status = "";
                    var courierEmail="";
                    if(this.employee!==null){
                        courId = this.employee.id;
                        courName = this.employee.name;
                        courMobile = this.employee.mobile;
                        if(this.employee.gender==="m")
                            gender = "Male";
                        else
                            gender = "Female";
                        if(this.employee.status===-10)
                            status = "Deleted";
                        else if(this.employee.status === -2)
                            status = "Dismissal";
                        else if(this.employee.status === -1)
                            status = "Abdicate";
                        else if(this.employee.status ===1)
                            status = "Leaving";
                        else
                            status = "In-Service";
                        if(this.employee.email!==null)
                            courierEmail = this.employee.email;
                    }
                    var courierName = $("<td>").append(courName);
                    var modelCourierName = courName;
                    var courierMobile = $("<td>").append(courMobile);
                    var modelCourierMoblie = courMobile;
//                    var courierStatus = this.Courierloyee.status;
                    var showCourierOp = $("<a href='#' title='Details' edbox data-box-target='#courier-show-box'"
                            +"' province='"+modelProvince+"' city='"+modelCity+"' district='"+modelDistrict+"' town='"+modelTown
                            +"' name='"+modelCourierName+"' gender='"+gender+"' mobile='"+modelCourierMoblie+"' email='"+courierEmail+"' status='"+status+"'></a>")
                            .append("<i class='fa fa-info' aria-hidden='true'></i>");
                    showCourierOp.click(function(){
                        $("#courier-show-province").empty();$("#courier-show-province").append(showCourierOp.attr("province"));
                        $("#courier-show-city").empty();$("#courier-show-city").append(showCourierOp.attr("city"));
                        $("#courier-show-district").empty();$("#courier-show-district").append(showCourierOp.attr("district"));
                        $("#courier-show-town").empty();$("#courier-show-town").append(showCourierOp.attr("town"));
                        $("#courier-show-name").empty();$("#courier-show-name").append(showCourierOp.attr("name"));
                        $("#courier-show-gender").empty();$("#courier-show-gender").append(showCourierOp.attr("gender"));
                        $("#courier-show-mobile").empty();$("#courier-show-mobile").append(showCourierOp.attr("mobile"));
                        $("#courier-show-email").empty();$("#courier-show-email").append(showCourierOp.attr("email"));
                        $("#courier-show-status").empty();$("#courier-show-status").append(showCourierOp.attr("status"));
                    });
                    showCourierOp.edbox();
                    
                    
                    var editCourierOp = $("<a href='#' edbox data-box-target='#courier-edit-box' province='"+modelProvince
                            +"' city='"+modelCity+"' district='"+modelDistrict+"' town='"+modelTown+"' townId='"+townId+"' courId='"+courId +"'></a>")
                            .append("<i class='fa fa-pencil' aria-hidden='true'></i");
                    editCourierOp.click(function(){
                        $("#disedit-courier-province").empty();$("#disedit-courier-province").append(editCourierOp.attr("province"));
                        $("#disedit-courier-city").empty();$("#disedit-courier-city").append(editCourierOp.attr("city"));
                        $("#disedit-courier-district").empty();$("#disedit-courier-district").append(editCourierOp.attr("district"));
                        $("#disedit-courier-town").empty();$("#disedit-courier-town").append(editCourierOp.attr("town"));
                        $("#disedit-town-id").val(editCourierOp.attr("townId"));
                        var cempId = editCourierOp.attr("courId");
                        if(cempId === "")
                            $("#edit-courier-name").selectPageClear();
                        else{
                            $('#edit-courier-name').val(cempId);$('#edit-courier-name').selectPageRefresh();
                        }
                    });
                    
                    editCourierOp.edbox();
                    
                    
                    var courierDel = $("<a href='#'edbox data-box-target='#courier-delete-box' townId='"+townId+"' title='Delete' class='red-a'></a>").append("<i class='fa fa-trash' aria-hidden='true'></i>");
                    courierDel.click(function(){
                        $("#courier-delete-town").val(courierDel.attr("townId"));
                    });
                    courierDel.edbox();
                    var courierOp = $("<td>").append(showCourierOp).append("&nbsp;&nbsp;&nbsp;").append(editCourierOp).append("&nbsp;&nbsp;&nbsp;").append(courierDel);
                    var courierRow = $("<tr>").append(courierCheckbox).append(province).append(city)
                            .append(district).append(town).append(courierName).append(courierMobile).append(courierOp);
                    if(rowNum%2===0)
                        courierRow.addClass("td-bk");
                    $("#courier-table-body").append(courierRow);
                });
            };
            $("#search-courier").click(function(){
                    $("#search-c-province").val($("#sh-province").val());
                    $("#search-c-city").val($("#sh-city").val());
                    $("#search-c-district").val($("#sh-district").val());
                    $("#search-c-town").val($("#sh-town").val());
                    $("#search-c-page").val(1);
                    getCourierList();
                    
                });
            function updateCourier(){
                $.ajax({
                    url: "${pageContext.request.contextPath}/courier/change_courier.do",
                    data: {
                        "courierId": $("#edit-courier-name").val(),
                        "townId": $("#disedit-town-id").val(),
                    },
                    type: "POST",
                    dataType: "json",
                    success: function(result) {
                        if(result.status === 1) {
                            $("#bt-edit-courier-cancel").click();
                            getCourierList();
                        }else{
                            alert("更改失败！");
                        }
                    },
                    error: function(){
                        $("#edit-emp-error-msg").empty();
                        $("#edit-emp-error-msg").append("Oppp, something goes wrong(Please select a valid birth)!");
                    }
                });
            }
            
            function deleteCourier(){
                $.ajax({
                    url: "${pageContext.request.contextPath}/courier/delete_courier.do",
                    data: {
                        "id": $("#courier-delete-town").val(),
                    },
                    type: "POST",
                    dataType: "json",
                    success: function(result) {
                        if(result.status === 1) {
                            $("#bt-delete-courier-cancel").click();
                            getCourierList();
                        }else{
                            $("#bt-delete-courier-cancel").click();
                            alert("删除失败！");
                        }
                    },
                    error: function(){
                        alert(result.msg);
                    }
                });
            }
            
            function selectAllCourier() {
                if($("#select-all-bt").attr("select")==="1"){
                    $("input[name='delCourier']").each(function(){
                        $(this).prop("checked", true);
                    });
                    $("#select-all-bt").attr("select", "0");
                }else{
                    $("input[name='delCourier']").each(function(){
                        $(this).prop("checked", false);
                    });
                    $("#select-all-bt").attr("select", "1");
                }
            }
            
            function batchDelete(){
                var delCouriers = new Array();
                $("input[name='delCourier']:checked").each(function(){
                    delCouriers.push($(this).val());
                });
                if(delCouriers.length === 0){
                    alert("Sorry, you didn't select any district!");
                    $("#bt-batch-delete-emp-cancel").click();
                    return;
                }
                $.ajax({
                    url: "${pageContext.request.contextPath}/courier/batch_delete_courier.do",
                    data: {
                        "idArray": delCouriers.toString()
                    },
                    type: "POST",
                    dataType: "json",
                    success: function(result) {
                        if(result.status === 1) {
                            $("#bt-delete-courier-cancel").click();
                            getCourierList();
                        }else{
                            $("#bt-delete-courier-cancel").click();
                            alert("删除失败！");
                            
                        }
                    },
                    error: function(){
                        alert(result.msg);
                    }
                });
            }

            $("#uploadAreaInfo").click(function(){
            var formData = new FormData($('#uploadForm')[0]);  
            $.ajax({  
                type: 'post',  
                url: "${pageContext.request.contextPath}/area/upload_file.do",  
                data: formData,
                contentType:false,
                processData: false,
            success:function (data) {  
                alert("上传成功");  
            },
            error:function () {  
                alert("上传失败");  
            }
        });  
        });
            
           
            
            
            
            
            
            
            
        </script>
    </body>
</html>
